package org.hamster.common.aggrid.example;

import org.hamster.common.aggrid.JpaAgGridService;
import org.hamster.common.aggrid.model.GetRowsRequest;
import org.hamster.common.aggrid.model.GetRowsResponse;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;

/**
 * Example controller showing how to use the JPA ag-Grid service
 */
public class JpaExampleController {
    
    @PersistenceContext
    private EntityManager entityManager;
    
    /**
     * Handle ag-Grid getRows request using JPA
     * 
     * @param request The request from ag-Grid
     * @return Response with data for the requested block
     */
    public GetRowsResponse getRows(GetRowsRequest request) {
        JpaAgGridService<ExampleEntity> jpaAgGridService = new JpaAgGridService<>(entityManager, ExampleEntity.class);
        return jpaAgGridService.getRows(request);
    }
}